<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<c:set var="ctx" value="${pageContext.request.contextPath}"/>
<!DOCTYPE html>
<html lang="en">
    <head>        
        <!-- META SECTION -->
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="viewport" content="width=device-width, initial-scale=1" />
        
        <link rel="icon" href="favicon.ico" type="image/x-icon" />
        <!-- END META SECTION -->
        
        <!-- CSS INCLUDE -->        
        <link rel="stylesheet" href="${ctx}/rs/css/bootstrap-table.css" />
        <link rel="stylesheet" href="${ctx}/rs/css/main.css" />
        <link id="theme" rel="stylesheet" href="${ctx}/rs/joli/css/theme-default.css" />
        <link rel="stylesheet" type="text/css" href="${ctx}/rs/css/custheme.css" />
        <!-- EOF CSS INCLUDE -->       
    </head>
<body>
    <style>
      .adStatusBtn {padding-top: 10px;padding-bottom: 20px;}
    .adStatusBtn button { margin-left: 20px; margin-right: 20px; }
    .adStatusBtn button.current { color: #ff615f;font-weight: bold; }
    </style>
    <!-- START PAGE CONTAINER -->
	<div class="page-container">
		<!-- 引入左菜单部分 -->
		<jsp:include page="../joli/menu.jsp"></jsp:include>

		<!-- START PAGE CONTENT -->
		<div class="page-content">

			<jsp:include page="../joli/top.jsp"></jsp:include>

			<!-- START BREADCRUMB -->
			<ul class="breadcrumb">
				<li><a href="#">套餐管理</a></li>
				<li class="active">套餐接单</li>
			</ul>
			<!-- END BREADCRUMB -->
			<!-- PAGE CONTENT WRAPPER -->
			<div class="page-content-wrap">
			<div class="row">
			
          
                <div class="panel panel-white panel-cus f-mt10">
                     <div class="panel-body">
                         <dl class="m-cus-select">
                             <dt class="l-left">投放状态</dt>
	                             <dd class="l-right adStatusBtn">
		                             <span class="u-item current" value="">全部</span>
		                             <span class="u-item" value="0">新建待审</span>
		                             <span class="u-item" value="2">审核通过</span>
		                             <span class="u-item" value="1">审核不通过</span>
		                             <span class="u-item" value="3">方案待确定</span>
		                             <span class="u-item" value="4">待投放</span>
		                             <span class="u-item" value="5">待确认投放</span>
		                             <span class="u-item" value="6">交易成功</span>
	                             </dd>
                         </dl>
                     </div>
                </div>    
          
				<div class="container-fluid">
						
		广告主： <input type="text" class="srt-put1 mr10 widput1"
			placeholder="搜索广告主" id="key" name="key" /> 套餐名称&nbsp;: <input
			type="text" class="srt-put1 mr10 widput1" placeholder="请输入套餐名称"
			id="planName" name="planName" />
		<button class="btn btn-primary btn-sm srt-btn active"
			onclick="refresh()">搜索</button>
	</div>
</div>
</div>
	<table id="table" cellpadding="0" cellspacing="0" data-toggle="table" data-toolbar="#toolbar"
                                data-url="${ctx}/TblComboPlanInfo/page.htm"
                                data-cache="false"
                                data-pagination="true" 
                                data-side-pagination="server"
                                data-page-list="[10, 20, 50, 100]"
                                data-page-size="20"  
                                data-query-params="queryParams">
                                <thead>
                                    <tr class="tab-th">
                                        <th data-field="planId" class="col-md-1">ID</th>
                                        <th data-field="userName" class="col-md-1" data-formatter="ToRole" >广告主</th>
                                        <th data-field="planName" class="col-md-2"  class="col-md-2">套餐名称</th>
                                        <th data-field="createTime" class="col-md-2" data-formatter="timeFormatter" class="col-md-2">提交时间</th>
                                        <th data-field="comboPrice"  class="col-md-2" >总价</th>
                                        <th data-field="planStatus"  class="col-md-1" data-formatter="statusFormatter">状态</th>
                                        <th data-field="action" data-formatter="actionFormatter" class="col-md-3">操作</th>
                                    </tr>
                                </thead>
                            </table>
                        </div>
                    </div>
                </div>
        </div>
       
    <div class="modal fade" id="modal1" role="dialog" aria-labelledby="gridSystemModalLabel" data-backdrop="static" >
      <div class="modal-dialog">
        <div class="modal-content">
          <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
            <h4 class="modal-title">审核不通过</h4>
          </div>
          <div class="modal-body">
          <form  class="form-horizontal">
             <div class="form-group">
                <label for="recipient-name" class="control-label col-sm-2">备注</label>
                <div class="col-sm-10">
                <textarea class="form-control postRemark"  row = 3 style="width:300px;" placeholder=" 请输入不超过140不通过的理由 "></textarea>
                <span class="help-block col-sm-4" id="valierr" style="color:#FF9966">*</span>
                </div>
              </div>
            </form>  
          </div>
          <div class="modal-footer">
            <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
            <button type="button" class="btn btn-success btnAjax">确认</button>
          </div>
        </div>
      </div>
    </div>

    <!-- 引入所有joli的脚本 -->
    <jsp:include page="../joli/scripts.jsp"></jsp:include>
    <!-- 引入页面需要的脚本 -->
    <script type="text/javascript" src="${ctx}/rs/js/bootstrapQ.min.js"></script>
    <script src="${ctx}/rs/js/bootstrap-table.js"></script>
    <script src="${ctx}/rs/js/bootstrap-table-zh-CN.js"></script>
    <script src="${ctx}/rs/js/jquery.formatDate.js"></script>
    <script src="${ctx}/rs/js/my97DatePicker/WdatePicker.js"></script>
    <script type="text/javascript" src="${ctx}/rs/js/session-out-error.js"></script>
    <script>
   
           var ps = '';
    $(".adStatusBtn span").on('click',function(){
           $(this).addClass('current').siblings('span').removeClass('current');
           var status =  $(".adStatusBtn .current").attr('value')
           ps = status;
           refresh(0,20,status)
      }); 
      activeMenu($("#menu_setMeal_1"));
      var $table = $('#table');
      
      $table.on('click-row.bs.table', function (e, row, $element) {
            $table.bootstrapTable('uncheckAll');
            $table.bootstrapTable('check', $element.index());
      });
      
      $table.bootstrapTable({
          height: getHeight()
      });
        
      //获取分辨率高度
        function getHeight() {
            return window.screen.height - 308;
        }
        
        $(window).resize(function () {
        $table.bootstrapTable('resetView',{height: getHeight()});
      });
        
        //初始化刷新
         function refresh(pageIndex,selectPage,planStatus){
        	if(planStatus == null){
        	    var planStatus1 = "";
        	}
        	var key = $("#key").val();
             var planName = $("#planName").val();
            if(!pageIndex && !selectPage){
                pageIndex = 0;
                selectPage = 0;
            }
            var pageSize = $table.bootstrapTable('getOptions').pageSize;
            pageIndex=pageIndex*pageSize;
            $table.bootstrapTable('refresh', {
                silent: true,
                cache : false,
                url: '${ctx}/TblComboPlanInfo/page.htm',
                query: {
                	key : encodeURI(key),
                	planName :encodeURI(planName),
                    pageIndex : pageIndex,
                    pageSize : pageSize,
                    planStatus : planStatus1
                }
           });
            $table.bootstrapTable('selectPage', selectPage);
        }
        
        function queryParams(params) {
        	var key = $("#key").val();
            var planName = $("#planName").val();
            var planStatus = $("#planStatus").val();
            return {
            	key : encodeURI(key),
            	planName : encodeURI(planName),
            	planStatus : ps,
                pageIndex : params.offset,
                pageSize : params.limit
            };
        }
        function ToRole(value,row,index){
        	if(value){
        		return value;
        	}else{
        		return "--";
        	}
        }
        function timeFormatter(value, row, index){
             if(value){
                 return $.formatDate("yyyy-MM-dd HH:mm:ss", new Date(value));
             }
             return "--";
        }
             
        function actionFormatter(value, row, index){
        	 var bak = '';
             if(row.planStatus == "0"){
                 bak =  '<a class="mr15" href="javascript:detail('+row.planId+')">查看</a><a class="mr15" href="javascript:update('+row.planId+',2)">通过</a><a class="mr15" href="javascript:update('+row.planId+',1)">不通过</a>';
             }else if(row.planStatus== "2"){
                 bak =  '<a class="mr15" href="javascript:detail('+row.planId+')">查看</a><a class="mr15" href="javascript:upFile('+row.planId+',2)">上传广告方案</a>';
             }else if(row.planStatus== "1"){
                 bak =  '<a class="mr15" href="javascript:detail('+row.planId+')">查看</a><a class="mr15" href="javascript:queryUp('+row.planId+')">不通过原由</a><a class="mr15" href="javascript:update('+row.planId+',10)">删除</a>';
             }else if(row.planStatus== "3"){
                 bak =  '<a class="mr15" href="javascript:detail('+row.planId+')">查看</a><a class="mr15" target="_blank" download = "1" href="'+row.postPackage+'">查看广告方案</a><a class="mr15" href="javascript:upFile('+row.planId+')">上传广告方案</a>';
             }else if(row.planStatus== "4"){
                 bak =  '<a class="mr15" href="javascript:detail('+row.planId+')">查看</a><a class="mr15"  href="javascript:TF('+row.planId+')">已投</a><a target="_blank" class="mr15" download = "'+row.postPackage+'" href="'+row.postPackage+'">查看广告方案</a>';
             }else if(row.planStatus== "5"){
                 bak =  '<a class="mr15" href="javascript:detail('+row.planId+')">查看</a><a class="mr15" href="javascript:queryTF('+row.planId+')">查看投放证明</a><a  target="_blank" class="mr15" download = "1" href="'+row.postPackage+'">查看广告方案</a>';
             }else if(row.planStatus== "6"){
                 bak =  '<a class="mr15" href="javascript:detail('+row.planId+')">查看</a><a class="mr15" href="javascript:queryTF('+row.planId+')">查看投放证明</a><a target="_blank" class="mr15" download = "1" href="'+row.postPackage+'">查看广告方案</a>';
             }
             return  bak; 
        }
        
        function statusFormatter(value,index,row){
            var bak = '';
            if(value == "0"){
                bak = "新建待审";
            }else if(value== "2"){
                bak = "审核通过";
            }else if(value== "1"){
                bak = "审核不通过";
            }else if(value== "3"){
                bak = "方案待确认";
            }else if(value== "4"){
                bak = "待投放";
            }else if(value== "5"){
                bak = "待确认投放";
            }else if(value== "6"){
                bak = "交易成功";
            }else if(value== "9"){
                bak = "未完成";
            }
            return  bak;
        }
        
        function detail(id) {
            var pageNumber = $table.bootstrapTable('getOptions').pageNumber;
            var pageIndex = pageNumber - 1;
            bootstrapQ.dialog({
                url : '${ctx}/TblComboPlanInfo/detail.htm?id='+id,
                title : '查看广告内容',
                width: "720px",
                close : 'true',
                hidebtn : 'true'
            },function(){
                //回调触发关闭窗口
                $("#bsmodal").modal("hide");
            });
        };
        function update(id,status){
            var pageNumber = $table.bootstrapTable('getOptions').pageNumber;
            var pageIndex = pageNumber - 1;
              var reason ="";
           if(status==2){
               bootstrapQ.confirm('确定通过？',function(){
                   $.ajax({
                      url: "${ctx}/TblComboPlanInfo/update.htm",
                     type: 'POST',
                     data: {
                         id:id,
                         reason:reason,
                         status:status
                     },
                       success: function (text) {
                           bootstrapQ.msg({
                               msg  : '操作成功！',
                               type : 'success',
                               time : 2000
                           });
                           refresh();
                       },
                       error: function () {
                           bootstrapQ.msg({
                               msg  : '操作失败！',
                               type : 'danger',
                               time : 2000
                           });
                           refresh();
                       }
                   });
               },null);
           }else if(status==1){
        	   $("#modal1").modal("show");
        	   $(".btnAjax").on('click',function(){
                   var postRemark = $(".postRemark").val();
                   if(!postRemark){
                         alert("请填写有效的回拒说明！");
                         return;
                     } if(postRemark.length>140){
                         alert("理由不能超过140字！");
                         return;
                     }
               bootstrapQ.confirm('确定不通过该单?',function(){
                     $.ajax({
                          url: "${ctx}/TblComboPlanInfo/update.htm", 
                         type: 'POST',
                         data: {
                             id:id,
                             reason: postRemark,
                             status:status
                         },
                           success: function (text) {
                               bootstrapQ.msg({
                                   msg  : '操作成功！',
                                   type : 'success',
                                   time : 2000
                               });
                               setTimeout("window.location.reload(true)",2000);
                           },
                           error: function () {
                               bootstrapQ.msg({
                                   msg  : '操作失败！',
                                   type : 'danger',
                                   time : 2000
                               });
                               setTimeout("window.location.reload(true)",1000);
                           } 
                     }); 
                  });
        	   })
            }if(status==10){
                bootstrapQ.confirm('确定删除该单？',function(){
                    $.ajax({
                       url: "${ctx}/TblComboPlanInfo/update.htm",
                      type: 'POST',
                      data: {
                          id:id,
                          reason:reason,
                          status:status
                      },
                        success: function (text) {
                            bootstrapQ.msg({
                                msg  : '操作成功！',
                                type : 'success',
                                time : 2000
                            });
                            refresh();
                        },
                        error: function () {
                            bootstrapQ.msg({
                                msg  : '操作失败！',
                                type : 'danger',
                                time : 2000
                            });
                            refresh();
                        }
                    });
                },null);
            }
        }
        
        function queryUp(id){
        	 var pageNumber = $table.bootstrapTable('getOptions').pageNumber;
             var pageIndex = pageNumber - 1;
             bootstrapQ.dialog({
                 url : '${ctx}/TblComboPlanInfo/queryUp.htm?id='+id,
                 title : '不通过原由',
                 width: "600px",
                 close : 'true',
                 hidebtn : '600'
             },function(){
                 //回调触发关闭窗口
                 $("#bsmodal").modal("hide");
             });
        }
        function upFile(id){
        	bootstrapQ.dialog({
                url : '${ctx}/TblComboPlanInfo/upFile.htm?id='+id,
                title : '上传广告方案',
                width: "400px",
                close : 'true',
                hidebtn : 'true'
            },function(){
                //回调触发关闭窗口
                $("#bsmodal").modal("hide");
                refresh();
            });
        }
//         function downFile (id) {
//         	debugger
//         	var url = encodeURI(id);
//             window.location.href ="${ctx}/TblComboPlanInfo/downFile.htm?urlString="+url;
//             window.location.href ="${ctx}/TblComboPlanInfo/downFile.htm

//             window.location.href= "${ctx}/contentTag/control.htm?providerCode="+providerCode+"&pid="+row.id+"&cpname="+cpname;
//         }
        function TF(id){
        	bootstrapQ.dialog({
                url : '${ctx}/TblComboPlanInfo/tf.htm?id='+id,
                title : '已投',
                width: "600px",
                close : 'true',
                hidebtn : 'true'
            },function(){
                //回调触发关闭窗口
                $("#bsmodal").modal("hide");
                refresh();
            });
        }
        function queryTF(id){
        	bootstrapQ.dialog({
                url : "${ctx}/TblComboPlanInfo/queryTF.htm?id="+ id,
                title : "投放证明",
                width: '720px',
                close : 'true',
                hidebtn : 'true'
            },function(){
                //回调触发关闭窗口
                $("#bsmodal").modal("hide");
                refresh();
            });
        	
        }
    </script>
</body>
</html>